<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Contents extends Admin_Controller {

	public $folder = 'contents/';
	
	public function __construct()
	{
		parent::__construct();
		$this->load->model('content_model');
		$this->load->library('form_validation');
	}
	
	// ------------------------------------------------------------------------
	
	public function index()
	{
		redirect('contents/all');
	}
	
	// ------------------------------------------------------------------------
	
	public function create_content()
	{
		if ($this->input->is_ajax_request())
		{
			$this->form_validation->set_rules('page_title', '<strong>Title</strong>', 'required|trim');
			$this->form_validation->set_rules('meta_description', '<strong>Meta Content</strong>', 'trim');
			$this->form_validation->set_rules('cat', '<strong>Type</strong>', 'required|exists[content_categories.content_category_id]');
			$this->form_validation->set_rules('category', '<strong>Category</strong>', 'required|exists[content_categories.content_category_id]');
			$this->form_validation->set_rules('websites', '<strong>Website</strong>', 'required|strtoupper|exists[websites.site_code]');
			$this->form_validation->set_rules('content', '<strong>Content</strong>', 'required');
			
			if ($this->form_validation->run())
			{
				$post = array(
					'title'					=> $this->input->post('page_title', TRUE),
					'meta_description'		=> $this->input->post('meta_description', TRUE),
					'html_code'				=> $this->input->post('content'),
					'published'				=> $this->input->post('published', TRUE) ? $this->input->post('published', TRUE) : 'n',
					'site_code'				=> $this->input->post('websites', TRUE),
					'content_category_id'	=> $this->input->post('category', TRUE)
				);
				
				$query = $this->content_model->create_content($post);
				
				$this->log_action('c', 'Content ID #' . $query['content_id']);
				$this->response(TRUE, 'redirect', '<p>New <strong>Content</strong> successfully created.</p>', site_url('contents/all'));
			}
			
			$this->response(FALSE, 'error', validation_errors());
		}
		
		$data = array(
			'title'			=> 'Create Content',
			'content'		=> $this->folder . 'create_content',
			'active'		=> 'contents',
			'websites'		=> $this->website_model->list_user_websites($this->user),
			'categories'	=> $this->content_model->list_categories(array('ancestor' => 0))
		);
		
		$this->load->view($this->tpl, $data);
	}
	
	// ------------------------------------------------------------------------
	
	public function all()
	{
		$this->load->helper('date');
		
		$config = array(
			'base_url'		=> site_url('contents/all'),
			'total_rows'	=> $this->content_model->count_contents('', TRUE),
			'per_page'		=> 30,
			'uri_segment'	=> 3
		);
		
		$uri = $this->uri->segment($config['uri_segment']);
		
		$data = array(
			'title'			=> 'View Contents',
			'content'		=> $this->folder . 'all',
			'active'		=> 'contents',
			'pages'			=> !$config['total_rows'] ? FALSE : $this->content_model->list_contents($config['per_page'], $uri, 'updated desc, created desc', '', '*', TRUE)
		);
		
		$this->load->library('pagination', $config);
		$this->load->view($this->tpl, $data);
	}
	
	// ------------------------------------------------------------------------v
	
	public function edit_content($page_id = '')
	{
		if ($page_id)
		{
			$page = $this->content_model->get_content($page_id, 'content_id', '*', TRUE);
			
			if ($page)
			{
				if ($this->input->is_ajax_request())
				{
					$this->form_validation->set_rules('page_title', '<strong>Title</strong>', 'required|trim');
					$this->form_validation->set_rules('meta_description', '<strong>Meta Content</strong>', 'trim');
					$this->form_validation->set_rules('cat', '<strong>Type</strong>', 'required|exists[content_categories.content_category_id]');
					$this->form_validation->set_rules('category', '<strong>Category</strong>', 'required|exists[content_categories.content_category_id]');
					$this->form_validation->set_rules('websites', '<strong>Website</strong>', 'required|strtoupper|exists[websites.site_code]');
					$this->form_validation->set_rules('content', '<strong>Content</strong>', 'required');
					
					if ($this->form_validation->run())
					{
						$post = array(
							'title'					=> $this->input->post('page_title', TRUE),
							'meta_description'		=> $this->input->post('meta_description', TRUE),
							'html_code'				=> $this->input->post('content'),
							'published'				=> $this->input->post('published', TRUE) ? $this->input->post('published', TRUE) : 'n',
							'site_code'				=> $this->input->post('websites', TRUE),
							'content_category_id'	=> $this->input->post('category', TRUE)
						);
						
						$this->content_model->update_content($post, $page_id);
						
						$this->log_action('u', 'Content ID #' .$page_id);
						$this->response(TRUE, 'redirect', '<p><strong>Content</strong> successfully updated.</p>', site_url('contents/all'));
					}
					
					$this->response(FALSE, 'error', validation_errors());
				}
				
				$data = array(
					'title'			=> 'Edit Content',
					'content'		=> $this->folder . 'edit_content',
					'active'		=> 'contents',
					'page'			=> $page,
					'websites'		=> $this->website_model->list_user_websites($this->user),
					'categories'	=> $this->content_model->list_categories(array('ancestor' => 0))
				);
				
				return $this->load->view($this->tpl, $data);
			}
		}
		
		show_404();
	}
	
	// ------------------------------------------------------------------------
	
	public function delete_content($content_id = '')
	{
		if ($this->input->is_ajax_request())
		{
			if ($content_id)
			{
				$content = $this->content_model->get_content($content_id, 'content_id', '*', TRUE);
				
				if ($content)
				{
					$this->content_model->delete_content($content_id);
					
					$this->log_action('d', 'Content ID #' . $content_id);
					$this->response(TRUE);
				}
			}
		}
		
		show_404();
	}
	
	// ------------------------------------------------------------------------
	
	public function ajax_list_categories($cat_id = '')
	{
		if ($this->input->is_ajax_request())
		{
			if ($cat_id)
			{
				$query = $this->content_model->list_child_categories($cat_id);
				$this->response(TRUE, 'custom', $query);
			}
			
			return;
		}
		
		show_404();
	}
	
	// ------------------------------------------------------------------------
	
	public function ajax_list_parent_categories($cat_id = '')
	{
		if ($this->input->is_ajax_request())
		{
			if ($cat_id)
			{
				$query = $this->content_model->list_categories(array('ancestor' => $cat_id, 'parent_category' => 0));
				$this->response(TRUE, 'custom', $query);
			}
			
			return;
		}
		
		show_404();
	}
	
	// ------------------------------------------------------------------------
	
	public function content_categories()
	{
		$data = array(
			'title'			=> 'View Content Categories',
			'content'		=> $this->folder . 'categories',
			'active'		=> 'contents',
			'categories'	=> $this->content_model->list_categories('', 'ancestor, parent_category, name')
		);
		
		$this->load->view($this->tpl, $data);
	}
	
	// ------------------------------------------------------------------------
	
	public function create_category()
	{
		if ($this->input->is_ajax_request())
		{
			$this->form_validation->set_rules('category_name', '<strong>Name</strong>', 'required|trim');
			$this->form_validation->set_rules('cat', '<strong>Type</strong>', 'exists[content_categories.content_category_id]');
			$this->form_validation->set_rules('category', '<strong>Category</strong>', 'exists[content_categories.content_category_id]');
			
			if ($this->form_validation->run())
			{
				$post = array(
					'name'				=> $this->input->post('category_name', TRUE),
					'parent_category'	=> $this->input->post('category', TRUE),
					'ancestor'			=> $this->input->post('cat', TRUE)
				);
				
				$query = $this->content_model->create_category($post);
				
				$this->log_action('c', 'Category ID #' . $query['content_category_id']);
				$this->response(TRUE, 'redirect', '<p>New <strong>Category</strong> successfully created.</p>', site_url('contents/content_categories'));
			}
			
			$this->response(FALSE, 'error', validation_errors());
		}
		
		$data = array(
			'title'			=> 'Create Category',
			'content'		=> $this->folder . 'create_category',
			'active'		=> 'contents',
			'categories'	=> $this->content_model->list_categories(array('ancestor' => 0), 'name')
		);
		
		$this->load->view($this->tpl, $data);
	}
	
	// ------------------------------------------------------------------------
	
	public function edit_category($cat_id = '')
	{
		if ($cat_id)
		{
			$cat = $this->content_model->get_category($cat_id);
			
			if ($cat)
			{
				if ($this->input->is_ajax_request())
				{
					$this->form_validation->set_rules('category_name', '<strong>Name</strong>', 'required|trim');
					$this->form_validation->set_rules('cat', '<strong>Type</strong>', 'exists[content_categories.content_category_id]');
					$this->form_validation->set_rules('category', '<strong>Category</strong>', 'exists[content_categories.content_category_id]');
					
					if ($this->form_validation->run())
					{
						$post = array(
							'name'				=> $this->input->post('category_name', TRUE),
							'parent_category'	=> $this->input->post('category', TRUE),
							'ancestor'			=> $this->input->post('cat', TRUE)
						);
						
						$this->content_model->update_category($post, $cat_id);
						
						$this->log_action('u', 'Category ID #' . $cat_id);
						$this->response(TRUE, 'redirect', '<p><strong>Category</strong> successfully updated.</p>', site_url('contents/content_categories'));
					}
					
					$this->response(FALSE, 'error', validation_errors());
				}
				
				$data = array(
					'title'			=> 'Edit Category',
					'content'		=> $this->folder . 'edit_category',
					'active'		=> 'contents',
					'category'		=> $cat,
					'categories'	=> $this->content_model->list_categories(array('ancestor' => 0), 'name')
				);
				
				return $this->load->view($this->tpl, $data);
			}
		}
		
		show_404();
	}
	
	// ------------------------------------------------------------------------
	
	public function delete_category($cat_id = '')
	{
		if ($this->input->is_ajax_request())
		{
			if ($cat_id)
			{
				$cat = $this->content_model->get_category($cat_id);
				
				if ($cat)
				{
					$this->content_model->delete_category($cat_id);
					
					$this->log_action('d', 'Category ID #' . $cat_id);
					$this->response(TRUE);
				}
			}
		}
		
		show_404();
	}
	
	// ------------------------------------------------------------------------
	
	public function create_poll()
	{
		if ($this->input->is_ajax_request())
		{
			$this->form_validation->set_rules('question', '<strong>Question</strong>', 'required|trim');
			$this->form_validation->set_rules('website', '<strong>Website</strong>', 'required|exists[websites.site_code]');
			$this->form_validation->set_rules('answer[]', '<strong>Answers</strong>', 'required');
			
			if ($this->form_validation->run())
			{
				$post = array(
					'question_title'	=> $this->input->post('question', TRUE),
					'site_code'			=> $this->input->post('website', TRUE),
					'published'			=> $this->input->post('published', TRUE)
				);
				
				$query = $this->content_model->create_poll($post, $this->input->post('answer', TRUE));
				
				$this->log_action('c', 'Poll ID #'. $query);
				$this->response(TRUE, 'redirect', '<p>New <strong>Poll</strong> successfully created.</p>', site_url('contents/polls'));
			}
			
			$this->response(FALSE, 'error', validation_errors());
		}
		
		$data = array(
			'title'			=> 'Create Poll',
			'content'		=> $this->folder . 'create_poll',
			'active'		=> 'contents',
			'websites'		=> $this->website_model->list_user_websites($this->user)
		);
		
		$this->load->view($this->tpl, $data);
	}
	
	// ------------------------------------------------------------------------
	
	public function edit_poll($poll_id = '')
	{
		if ($poll_id)
		{
			$poll = $this->content_model->get_poll($poll_id);
			
			if ($poll)
			{
				if ($this->input->is_ajax_request())
				{
					$this->form_validation->set_rules('question', '<strong>Question</strong>', 'required|trim');
					$this->form_validation->set_rules('website', '<strong>Website</strong>', 'required|exists[websites.site_code]');
					$this->form_validation->set_rules('answer[]', '<strong>Answers</strong>', 'required');
					$this->form_validation->set_rules('answers', '<strong>Answers</strong>', 'required');
					
					if ($this->form_validation->run())
					{
						$post = array(
							'question_title'	=> $this->input->post('question', TRUE),
							'site_code'			=> $this->input->post('website', TRUE),
							'published'			=> $this->input->post('published', TRUE)
						);
						
						$query = $this->content_model->update_poll($post, $this->input->post('answers', TRUE), $poll_id);
						
						$this->log_action('u', 'Poll ID #'. $poll_id);
						$this->response(TRUE, 'redirect', '<p><strong>Poll</strong> successfully updated.</p>', site_url('contents/polls'));
					}
					
					$this->response(FALSE, 'error', validation_errors());
				}
				
				$data = array(
					'title'			=> 'Edit Poll',
					'content'		=> $this->folder . 'edit_poll',
					'active'		=> 'contents',
					'poll'			=> $poll,
					'websites'		=> $this->website_model->list_user_websites($this->user)
				);
				
				return $this->load->view($this->tpl, $data);
			}
		}
		
		show_404();
	}
	
	// ------------------------------------------------------------------------
	
	public function polls()
	{
		$config = array(
			'base_url'		=> site_url('contents/polls'),
			'total_rows'	=> $this->content_model->count_polls(TRUE),
			'per_page'		=> 30,
			'uri_segment'	=> 3
		);
		
		$uri = $this->uri->segment($config['uri_segment']);
		
		$data = array(
			'title'			=> 'View Polls',
			'content'		=> $this->folder . 'polls',
			'active'		=> 'contents',
			'polls'			=> $this->content_model->list_polls($config['per_page'], $uri, 'updated desc, created desc')
		);
		
		$this->load->library('pagination', $config);
		$this->load->view($this->tpl, $data);
	}
	
	// ------------------------------------------------------------------------
	
	public function delete_poll($poll_id = '')
	{
		if ($this->input->is_ajax_request())
		{
			if ($poll_id)
			{
				$poll = $this->content_model->get_poll($poll_id, 'poll_id', 'poll_id', TRUE);
				
				if ($poll)
				{
					$this->content_model->delete_poll($poll_id);
					
					$this->log_action('d', 'Poll ID #' . $poll_id);
					$this->response(TRUE);
				}
			}
		}
		
		show_404();
	}
	
	// ------------------------------------------------------------------------
	
	public function create_product_category()
	{
		if ($this->input->is_ajax_request())
		{
			$this->form_validation->set_rules('category_name', '<strong>Name</strong>', 'required|trim');
			$this->form_validation->set_rules('website', '<strong>Website</strong>', 'required|exists[websites.site_code]');
			
			if ($this->form_validation->run())
			{
				$post = array(
					'name'			=> $this->input->post('category_name', TRUE),
					'site_code'		=> $this->input->post('website', TRUE)
				);
				
				$query = $this->content_model->create_product_category($post);
				
				$this->log_action('c', 'Website Product Category ID #' . $query['site_prod_cat_id']);
				$this->response(TRUE, 'redirect', '<p>New <strong>Website Product Category</strong> successfully created.</p>', site_url('contents/product_categories'));
			}
			
			$this->response(FALSE, 'error', validation_errors());
		}
		
		$data = array(
			'title'			=> 'Create Website Product Category',
			'content'		=> $this->folder . 'create_product_category',
			'active'		=> 'contents',
			'websites'		=> $this->website_model->list_user_websites($this->user)
		);
		
		$this->load->view($this->tpl, $data);
	}
	
	// ------------------------------------------------------------------------
	
	public function product_categories()
	{
		$config = array(
			'base_url'		=> site_url('contents/product_categories'),
			'total_rows'	=> $this->content_model->count_product_categories(TRUE),
			'per_page'		=> 30,
			'uri_segment'	=> 3
		);
		
		$uri = $this->uri->segment($config['uri_segment']);
		
		$data = array(
			'title'			=> 'View Website Product Categories',
			'content'		=> $this->folder . 'product_categories',
			'active'		=> 'contents',
			'categories'	=> $this->content_model->list_product_categories($config['per_page'], $uri, 'created', '', '*', TRUE)
		);
		
		$this->load->library('pagination', $config);
		$this->load->view($this->tpl, $data);
	}
	
	// ------------------------------------------------------------------------
	
	public function create_product()
	{
		if ($this->input->is_ajax_request())
		{
			$this->form_validation->set_rules('product_name', '<strong>Name</strong>', 'required|trim');
			$this->form_validation->set_rules('website', '<strong>Website</strong>', 'required|exists[websites.site_code]');
			$this->form_validation->set_rules('label', '<strong>Label</strong>', 'required|exists[website_product_labels.site_prod_label_id]');
			
			if ($this->form_validation->run())
			{
				$post = array(
					'name'					=> $this->input->post('product_name', TRUE),
					'site_prod_label_id'	=> $this->input->post('label', TRUE),
					'blurb'					=> $this->input->post('blurb', TRUE),
					'description'			=> $this->input->post('description'),
					'published'				=> $this->input->post('published', TRUE)
				);
				
				$query = $this->content_model->create_product($post);
				
				$this->log_action('c', 'Website Product #' . $query['site_product_id']);
				$this->response(TRUE, 'redirect', '<p>New <strong>Product</strong> successfully created.</p>', site_url('contents/products'));
			}
			
			$this->response(FALSE, 'error', validation_errors());
		}
		
		$data = array(
			'title'			=> 'Create Website Product',
			'content'		=> $this->folder . 'create_product',
			'active'		=> 'contents',
			'websites'		=> $this->website_model->list_user_websites($this->user)
		);
		
		$this->load->view($this->tpl, $data);
	}
	
	// ------------------------------------------------------------------------
	
	public function edit_product_category($cat_id = '')
	{
		if ($cat_id)
		{
			$cat = $this->content_model->get_product_category($cat_id);
			
			if ($cat)
			{
				if ($this->input->is_ajax_request())
				{
					$this->form_validation->set_rules('category_name', '<strong>Name</strong>', 'required|trim');
					$this->form_validation->set_rules('website', '<strong>Website</strong>', 'required|exists[websites.site_code]');
					
					if ($this->form_validation->run())
					{
						$post = array(
							'name'			=> $this->input->post('category_name', TRUE),
							'site_code'		=> $this->input->post('website', TRUE)
						);
						
						$this->content_model->update_product_category($post, $cat_id);
						
						$this->log_action('u', 'Website Product Category #' . $cat_id);
						$this->response(TRUE, 'redirect', '<p><strong>Website Product Category</strong> successfully updated.</p>', site_url('contents/product_categories'));
					}
					
					$this->response(FALSE, 'error', validation_errors());
				}
				
				$data = array(
					'title'			=> 'Edit Product Category',
					'content'		=> $this->folder . 'edit_product_category',
					'active'		=> 'contents',
					'category'		=> $cat,
					'websites'		=> $this->website_model->list_user_websites($this->user)
				);
				
				return $this->load->view($this->tpl, $data);
			}
		}
		
		show_404();
	}
	
	// ------------------------------------------------------------------------
	
	public function delete_product_category($cat_id = '')
	{
		if ($this->input->is_ajax_request())
		{
			if ($cat_id)
			{
				$cat = $this->content_model->get_product_category($cat_id);
				
				if ($cat)
				{
					$this->content_model->delete_product_category($cat_id);
					
					$this->log_action('d', 'Website Product Category #'. $cat_id);
					$this->response(TRUE);
				}
			}
		}
		
		show_404();
	}
	
	// ------------------------------------------------------------------------
	
	public function create_product_label()
	{
		if ($this->input->is_ajax_request())
		{
			$this->form_validation->set_rules('label_name', '<strong>Name</strong>', 'required|trim');
			$this->form_validation->set_rules('website', '<strong>Website</strong>', 'required|exists[websites.site_code]');
			$this->form_validation->set_rules('category', '<strong>Category</strong>', 'required|exists[website_product_categories.site_prod_cat_id]');
			
			if ($this->form_validation->run())
			{
				$post = array(
					'name'				=> $this->input->post('label_name', TRUE),
					'site_prod_cat_id'	=> $this->input->post('category', TRUE),
					'description'		=> $this->input->post('description')
				);
				
				$query = $this->content_model->create_product_label($post);
				
				$this->log_action('c', 'Website Product Label ID #' . $query['site_prod_label_id']);
				$this->response(TRUE, 'redirect', '<p>New <strong>Website Product Label</strong> successfully created.</p>', site_url('contents/product_labels'));
			}
			
			$this->response(FALSE, 'error', validation_errors());
		}
		
		$data = array(
			'title'			=> 'Create Product Label',
			'content'		=> $this->folder . 'create_product_label',
			'active'		=> 'contents',
			'websites'		=> $this->website_model->list_user_websites($this->user)
		);
		
		$this->load->view($this->tpl, $data);
	}
	
	// ------------------------------------------------------------------------
	
	public function edit_product_label($label_id = '')
	{
		if ($label_id)
		{
			$label = $this->content_model->get_product_label($label_id);
			
			if ($label)
			{
				if ($this->input->is_ajax_request())
				{
					$this->form_validation->set_rules('label_name', '<strong>Name</strong>', 'required|trim');
					$this->form_validation->set_rules('website', '<strong>Website</strong>', 'required|exists[websites.site_code]');
					$this->form_validation->set_rules('category', '<strong>Category</strong>', 'required|exists[website_product_categories.site_prod_cat_id]');
					
					if ($this->form_validation->run())
					{
						$post = array(
							'name'				=> $this->input->post('label_name', TRUE),
							'site_prod_cat_id'	=> $this->input->post('category', TRUE),
							'description'		=> $this->input->post('description')
						);
						
						$this->content_model->update_product_label($post, $label_id);
						
						$this->log_action('u', 'Website Product Label ID #' . $label_id);
						$this->response(TRUE, 'redirect', '<p><strong>Website Product Label</strong> successfully updated.</p>', site_url('contents/product_labels'));
					}
					
					$this->response(FALSE, 'error', validation_errors());
				}
				
				
				$data = array(
					'title'			=> 'Edit Website Product Label',
					'content'		=> $this->folder . 'edit_product_label',
					'active'		=> 'contents',
					'label'			=> $label,
					'websites'		=> $this->website_model->list_user_websites($this->user)
				);
				
				return $this->load->view($this->tpl, $data);
			}
		}
		
		show_404();
	}
	
	// ------------------------------------------------------------------------
	
	public function product_labels()
	{
		$config = array(
			'base_url'		=> site_url('contents/product_labels'),
			'total_rows'	=> $this->content_model->count_product_labels(TRUE),
			'per_page'		=> 30,
			'uri_segment'	=> 3
		);
		
		$uri = $this->uri->segment($config['uri_segment']);
		
		$data = array(
			'title'			=> 'View Website Product Labels',
			'content'		=> $this->folder . 'product_labels',
			'active'		=> 'contents',
			'labels'		=> $this->content_model->list_product_labels($config['per_page'], $uri, 'created', '', '*', TRUE)
		);
		
		$this->load->library('pagination', $config);
		$this->load->view($this->tpl, $data);
	}
	
	// ------------------------------------------------------------------------
	
	public function products()
	{
		$config = array(
			'base_url'		=> site_url('contents/products'),
			'total_rows'	=> $this->content_model->count_products(TRUE),
			'per_page'		=> 30,
			'uri_segment'	=> 3
		);
		
		$uri = $this->uri->segment($config['uri_segment']);
		
		$data = array(
			'title'			=> 'View Website Products',
			'content'		=> $this->folder . 'products',
			'active'		=> 'contents',
			'products'		=> $this->content_model->list_products($config['per_page'], $uri, 'updated desc, created desc', '', '*', TRUE)
		);
		
		$this->load->library('pagination', $config);
		$this->load->view($this->tpl, $data);
	}
	
	// ------------------------------------------------------------------------
	
	public function edit_product($prod_id = '')
	{
		if ($prod_id)
		{
			$product = $this->content_model->get_product($prod_id);
			
			if ($product)
			{
				if ($this->input->is_ajax_request())
				{
					$this->form_validation->set_rules('product_name', '<strong>Name</strong>', 'required|trim');
					$this->form_validation->set_rules('website', '<strong>Website</strong>', 'required|exists[websites.site_code]');
					$this->form_validation->set_rules('label', '<strong>Label</strong>', 'required|exists[website_product_labels.site_prod_label_id]');
					
					if ($this->form_validation->run())
					{
						$post = array(
							'name'					=> $this->input->post('product_name', TRUE),
							'site_prod_label_id'	=> $this->input->post('label', TRUE),
							'blurb'					=> $this->input->post('blurb', TRUE),
							'description'			=> $this->input->post('description'),
							'published'				=> $this->input->post('published', TRUE)
						);
						
						$this->content_model->update_product($post, $prod_id);
						
						$this->log_action('u', 'Website Product ID #' . $prod_id);
						$this->response(TRUE, 'redirect', '<p><strong>Website Product</strong> successfully updated.</p>', site_url('contents/products'));
					}
					
					$this->response(FALSE, 'error', validation_errors());
				}
				
				$data = array(
					'title'			=> 'Edit Website Product',
					'content'		=> $this->folder . 'edit_product',
					'active'		=> 'contents',
					'product'		=> $product,
					'websites'		=> $this->website_model->list_user_websites($this->user)
				);
				
				return $this->load->view($this->tpl, $data);
			}
		}
		
		show_404();
	}
	
	// ------------------------------------------------------------------------
	
	public function delete_product_label($label_id = '')
	{
		if ($this->input->is_ajax_request())
		{
			if ($label_id)
			{
				$label = $this->content_model->get_product_label($label_id);
				
				if ($label)
				{
					$this->content_model->delete_product_label($label_id);
					
					$this->log_action('d', 'Website Product Label ID #' . $label_id);
					$this->response(TRUE);
				}
			}
		}
		
		show_404();
	}
	
	// ------------------------------------------------------------------------
	
	public function delete_product($prod_id = '')
	{
		if ($this->input->is_ajax_request())
		{
			if ($prod_id)
			{
				$product = $this->content_model->get_product($prod_id);
				
				if ($product)
				{
					$this->content_model->delete_product($prod_id);
					
					$this->log_action('d', 'Website Product ID #' . $prod_id);
					$this->response(TRUE);
				}
			}
		}
		
		show_404();
	}
	
	// ------------------------------------------------------------------------

}

/* End of file contents.php */
/* Location: ./application/controllers/contents.php */